const router = require('express').Router()
// let multer  = require('multer')
// let upload = multer({ dest: './public/uploads/' })
const upload = require("../utils/multer")
// 显示上传文件的页面
router.get("/upload",(req,res)=>{
    res.render("upload")
})

/* router.post("/upload",upload.single('img'),(req,res)=>{
    res.send("上传成功")
}) */


/* let storage = multer.diskStorage({
    destination: function (req, file, cb) {
      cb(null, './public/uploads/')
    },
    filename: function (req, file, cb) {
        // 切割得到后缀名
        let fileArr = file.originalname.split(".");
        let extname = fileArr[fileArr.length-1];
      cb(null, file.fieldname + '-' + Date.now()+"."+extname)
    }
  })
   
let upload = multer({ storage: storage }) */


/* router.post("/upload",upload.single('img'),(req,res)=>{
    res.send("上传成功")
})  */

router.post("/upload",upload.single('img'),(req,res)=>{
    res.send("上传成功")
})

module.exports = router